package net.lab1024.smartadmin.module.business.torqueConverterLambda.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaAddDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaQueryDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.dto.TorqueConverterLambdaUpdateDTO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.entity.TorqueConverterLambdaEntity;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.vo.TorqueConverterLambdaExcelVO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.domain.vo.TorqueConverterLambdaVO;
import net.lab1024.smartadmin.module.business.torqueConverterLambda.service.TorqueConverterLambdaService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 变矩器λ曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 变矩器λ曲线
 * @copyright (c)  变矩器λ曲线Inc. All rights reserved.
 * @date 2021-11-13 15:05:32
 * @since JDK1.8
 */
@RestController
@Api(tags = {"变矩器λ曲线"})
public class TorqueConverterLambdaController extends BaseController {

    @Autowired
    private TorqueConverterLambdaService torqueConverterLambdaService;

    @ApiOperation(value = "分页查询变矩器λ曲线",notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/page/query")
    public ResponseDTO<PageResultDTO<TorqueConverterLambdaVO>> queryByPage(@RequestBody TorqueConverterLambdaQueryDTO queryDTO) {
        return torqueConverterLambdaService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加变矩器λ曲线",notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/add")
    public ResponseDTO<String> add(@RequestBody @Validated TorqueConverterLambdaAddDTO addTO){

        // 保存之前先删除旧的数据
        torqueConverterLambdaService.delByTorqueConvertId(addTO.getTorqueConvertId());

        return torqueConverterLambdaService.add(addTO);
    }

    @ApiOperation(value="修改变矩器λ曲线",notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/update")
    public ResponseDTO<String> update(@RequestBody @Validated TorqueConverterLambdaUpdateDTO updateDTO){
        return torqueConverterLambdaService.update(updateDTO);
    }

    @ApiOperation(value = "根据变矩器id获取",notes = "@author wuhq")
    @GetMapping("/torqueConverterLambda/getByTorqueConvertId/{torqueConvertId}")
    public ResponseDTO<TorqueConverterLambdaEntity> getByTorqueConvertId(@PathVariable Long torqueConvertId) {
        return ResponseDTO.succData(torqueConverterLambdaService.getByTorqueConvertId(torqueConvertId));
    }

    @ApiOperation(value="批量删除变矩器λ曲线",notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return torqueConverterLambdaService.deleteByIds(idList);
    }



    @ApiOperation(value = "批量导出", notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<TorqueConverterLambdaExcelVO> torqueConverterLambdaList = torqueConverterLambdaService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("变矩器λ曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, TorqueConverterLambdaExcelVO.class, torqueConverterLambdaList);
        downloadExcel("变矩器λ曲线", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuhq")
    @PostMapping("/torqueConverterLambda/export/all")
    public void exportAll(@RequestBody @Validated TorqueConverterLambdaQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<TorqueConverterLambdaExcelVO> torqueConverterLambdaList = torqueConverterLambdaService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("变矩器λ曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, TorqueConverterLambdaExcelVO.class, torqueConverterLambdaList);
        downloadExcel("变矩器λ曲线", workbook, response);
    }

}
